package com.welfare.service;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.common.util.AJAXResultMessage;
import com.welfare.dao.WelfareRepository;
import com.welfare.entity.Welfare;

@Service
@Transactional
public class WelfareService implements IWelfareService {
	@Autowired
	private WelfareRepository welfareRepository;
	
	@Override
	public AJAXResultMessage saveOrUpdate(Welfare welfare) {
		welfareRepository.save(welfare);
		
		return new AJAXResultMessage(true,"操作成功");
	}

	@Override
	public void delete(Welfare welfare) {
		welfareRepository.delete(welfare);

	}

	@Override
	public Welfare findOne(Long id) {
		return welfareRepository.findOne(id);
	}

	@Override
	public List<Welfare> findAll() {
		return (List<Welfare>) welfareRepository.findAll();
	}

	@Override
	public void delete(List<Long> ids) {
		List<Welfare> welfareList = (List<Welfare>)welfareRepository.findAll(ids);
		welfareRepository.delete(welfareList);
	}

	@Override
	public Page<Welfare> findAll(Specification<Welfare> spec, Pageable pageable) {
		return welfareRepository.findAll(spec, pageable);
	}

}
